package com.tv.cms.utils;


import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Pattern;

public class TimeUtils {

	@SuppressWarnings("unused")
	public static Timestamp getCurrentTime() {
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// 可以方便地修改日期格式
		Timestamp time = new Timestamp(new Date().getTime());
		return time;
	}
 
	public static Timestamp getCurrentTime(String date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 可以方便地修改日期格式
		Timestamp time = null;
		try {
//			System.out.println((dateFormat.parse(date)).getTime());
			time = new Timestamp((dateFormat.parse(date)).getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return time;
	}
	
	/**
	 * 将date 转化为 Timestamp
	 * @param date
	 * @return
	 */
	public static Timestamp getTimestamp(Date date) {
		Timestamp time = null;
		time = new Timestamp(date.getTime());
		return time;
	}
	
	/**
	 * 格式化当前时间
	 * @param format 格式化规则
	 * @return String 格式化以后的Time字符串
	 */
	public static String getCurrentTimeStr(String format){
		if(StringUtils.isEmpty(format)){
			return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(new Date());
	}

	public static Timestamp getTimestampDate(String date) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		format.setLenient(false);
		try {
			Timestamp ts = new Timestamp(format.parse(date).getTime());
			return ts;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Timestamp getTimestampDateFmt(String date) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		format.setLenient(false);
		try {
			Timestamp ts = new Timestamp(format.parse(date).getTime());
			return ts;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * date和format格式必须一直
	 * @param date
	 * @return
	 */
	public static Timestamp getTimestampDate(String date, String formatStr) {
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		format.setLenient(false);
		try {
			Timestamp ts = new Timestamp(format.parse(date).getTime());
			return ts;
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

	public static Date convertToDate(String data) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");// 可以方便地修改日期格式
		Date ret;
		try {
			ret = dateFormat.parse(data);
			return ret;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * date和format格式必须一直
	 * @param format
	 * @return
	 */
	public static Date convertDate(String data, String format) {
		if(StringUtils.isBlank(format)){
			format = "yyyy-MM-dd HH:mm:ss";
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date langDate;
		try {
			langDate = sdf.parse(data);
			return langDate;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * date和format格式必须一直
	 * @param date
	 * @param format
	 * @return
	 */
	public static String formatStringDate(String date, String format) {
		String time = "";
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			time = sdf.format(sdf.parse(date));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return time;
	}
	/**
	 * Timestamp 格式转 String
	 * @param timestamp
	 * @param format
	 * @return
	 */
	public static String formatStringTimestamp(Timestamp timestamp, String format) {
		String time = "";
		try {
			DateFormat sdf = new SimpleDateFormat(format); 
			time = sdf.format(timestamp);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return time;
	}

	public static String converStringDate(Date date, String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		try {
			return sdf.format(date);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 几秒前，几分钟前，几小时前，几天前，几月前，几年前的java实现
	 */
	private static final long ONE_MINUTE = 60000L;  
    private static final long ONE_HOUR = 3600000L;  
    private static final long ONE_DAY = 86400000L;  
    private static final long ONE_WEEK = 604800000L;  
  
    private static final String ONE_SECOND_AGO = "秒前";  
    private static final String ONE_MINUTE_AGO = "分钟前";  
    private static final String ONE_HOUR_AGO = "小时前";  
    private static final String ONE_DAY_AGO = "天前";  
    private static final String ONE_MONTH_AGO = "月前";  
    private static final String ONE_YEAR_AGO = "年前";  
	public static String getTimeAgo(Date date){
		long delta = new Date().getTime() - date.getTime();  
        if (delta < 1L * ONE_MINUTE) {  
            long seconds = toSeconds(delta);  
            return (seconds <= 0 ? 1 : seconds) + ONE_SECOND_AGO;  
        }  
        if (delta < 45L * ONE_MINUTE) {  
            long minutes = toMinutes(delta);  
            return (minutes <= 0 ? 1 : minutes) + ONE_MINUTE_AGO;  
        }  
        if (delta < 24L * ONE_HOUR) {  
            long hours = toHours(delta);  
            return (hours <= 0 ? 1 : hours) + ONE_HOUR_AGO;  
        }  
        if (delta < 48L * ONE_HOUR) {  
            return "昨天";  
        }  
        if (delta < 30L * ONE_DAY) {  
            long days = toDays(delta);  
            return (days <= 0 ? 1 : days) + ONE_DAY_AGO;  
        }  
        if (delta < 12L * 4L * ONE_WEEK) {  
            long months = toMonths(delta);  
            return (months <= 0 ? 1 : months) + ONE_MONTH_AGO;  
        } else {  
            long years = toYears(delta);  
            return (years <= 0 ? 1 : years) + ONE_YEAR_AGO;  
        }  
		
	}
	private static long toSeconds(long date) {  
        return date / 1000L;  
    }  
  
    private static long toMinutes(long date) {  
        return toSeconds(date) / 60L;  
    }  
  
    private static long toHours(long date) {  
        return toMinutes(date) / 60L;  
    }  
  
    private static long toDays(long date) {  
        return toHours(date) / 24L;  
    }  
  
    private static long toMonths(long date) {  
        return toDays(date) / 30L;  
    }  
  
    private static long toYears(long date) {  
        return toMonths(date) / 365L;  
    }  
    
	/**
	 * 格式化时间 Locale是设置语言敏感操作
	 * 
	 * @param formatTime
	 * @return
	 */
	public static String getTimeStampNumberFormat(Timestamp formatTime) {
		SimpleDateFormat m_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
				new Locale("zh", "cn"));
		return m_format.format(formatTime);
	}

	public static String getDateFormat(Date date) {
		SimpleDateFormat m_format = new SimpleDateFormat("yyyy-MM-dd",
				new Locale("zh", "cn"));
		return m_format.format(date);
	}

	public static boolean checkLimitTime(Timestamp formatTime1,
			Timestamp formatTime2, int limit_time) {
		SimpleDateFormat timeformat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		long t1 = 0L;
		long t2 = 0L;
		try {
			t1 = timeformat.parse(getTimeStampNumberFormat(formatTime1))
					.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		try {
			t2 = timeformat.parse(getTimeStampNumberFormat(formatTime2))
					.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}

		// 因为t1-t2得到的是毫秒级,所以要初3600000得出小时.算天数或秒同理
		int hours = (int) ((t1 - t2) / 3600000);
		int minutes = (int) (((t1 - t2) / 1000 - hours * 3600) / 60);
		int second = (int) ((t1 - t2) / 1000 - hours * 3600 - minutes * 60);
		int sec = hours * 3600 + minutes * 60 + second;
		System.out.println(sec);
		System.out.println(limit_time);
		if (sec > limit_time)
			return true;
		return false;
	}

	/**
	 * 获取当前日期是星期几<br>
	 * 
	 * @param dt
	 * @return 当前日期是星期几
	 */
	public static String getWeekOfDate(Date dt) {
		String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
		Calendar cal = Calendar.getInstance();
		cal.setTime(dt);

		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;

		return weekDays[w];
	}

	/**
	 * 获取一个星期的第几天
	 * 
	 * @param dt
	 * @return
	 */
	public static int getWeekDays(Date dt) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(dt);

		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return w;
	}

	public static String getInterval(String createtime, String timeStr) { // 传入的时间格式必须类似于2012-8-21
		// 17:53:20这样的格式
		String interval = null;

		SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		ParsePosition pos = new ParsePosition(0);
		Date d1 = sd.parse(createtime, pos);

		// 用现在距离1970年的时间间隔new
		// Date().getTime()减去以前的时间距离1970年的时间间隔d1.getTime()得出的就是以前的时间与现在时间的时间间隔
		long time = new Date().getTime() - d1.getTime();// 得出的时间间隔是毫秒
		int hour = (int) (time / 3600000);
		if (time / 1000 < 10 && time / 1000 >= 0) {
			// 如果时间间隔小于10秒则显示“刚刚”time/10得出的时间间隔的单位是秒
			interval = "刚刚";
		} else if (hour < 24 && hour > 0) {
			// 如果时间间隔小于24小时则显示多少小时前
			int h = (int) (time / 3600000);// 得出的时间间隔的单位是小时
			interval = h + "小时前";

		} else if (time / 60000 < 60 && time / 60000 > 0) {
			// 如果时间间隔小于60分钟则显示多少分钟前
			int m = (int) ((time % 3600000) / 60000);// 得出的时间间隔的单位是分钟
			interval = m + "分钟前";

		} else if (time / 1000 < 60 && time / 1000 >= 0) {
			// 如果时间间隔小于60秒则显示多少秒前
			int se = (int) ((time % 60000) / 1000);
			interval = se + "秒前";

		} else {
			// 大于24小时，则显示正常的时间，但是不显示秒
			SimpleDateFormat sdf = new SimpleDateFormat(timeStr);
			ParsePosition pos2 = new ParsePosition(0);
			Date d2 = sdf.parse(createtime, pos2);
			interval = sdf.format(d2);
		}
		return interval;
	}

	public static String getInterval(String createtime) {
		return getInterval(createtime, "yyyy-MM-dd HH:mm");
	}

	/**
	 * 获取当天开始时间 ex:2015-03-03 00:00:00
	 * 
	 * @param day
	 *  当前时间往后多少天
	 * @return
	 */
	public static Date getCurrentStartTime(int day, Date date) {
		Calendar todayStart = Calendar.getInstance();
		if (date != null) {
			todayStart.setTime(date);
		}
		todayStart.set(Calendar.HOUR_OF_DAY, 0);
		todayStart.set(Calendar.MINUTE, 0);
		todayStart.set(Calendar.SECOND, 0);
		todayStart.set(Calendar.MILLISECOND, 0);
		todayStart.add(Calendar.DATE, day);
		return todayStart.getTime();
	}
	
	/**
	 * 获取当天开始时间
	 * 
	 *  当前时间往后多少小时
	 * @return
	 */
	public static Date getCurrentStartHour(int hour, Date date) {
		Calendar todayStart = Calendar.getInstance();
		if (date != null) {
			todayStart.setTime(date);
		}
		todayStart.add(Calendar.HOUR, hour);
		return todayStart.getTime();
	}

	
	/**
	 * 获取当天开始时间
	 *  当前时间往后多少分钟
	 * @return
	 */
	public static Date getCurrentStartMinute(int minute, Date date) {
		Calendar todayStart = Calendar.getInstance();
		if (date != null) {
			todayStart.setTime(date);
		}
		todayStart.add(Calendar.MINUTE, minute);
		return todayStart.getTime();
	}
	
	/**
	 * 获取当前结束时间 ex:2015-03-03 23:59:59
	 * 
	 * @param day
	 *            当前时间往后多少天
	 * @return
	 */
	public static Date getCurrentEndTime(int day, Date date) {
		Calendar todayStart = Calendar.getInstance();
		if (date != null) {
			todayStart.setTime(date);
		}
		todayStart.set(Calendar.HOUR_OF_DAY, 23);
		todayStart.set(Calendar.MINUTE, 59);
		todayStart.set(Calendar.SECOND, 59);
		todayStart.set(Calendar.MILLISECOND, 59);
		todayStart.add(Calendar.DATE, day);
		return todayStart.getTime();
	}

	/**
	 * 
	 * @param dateStr
	 *            默认 yyyy/MM/dd HH:mm
	 * @return
	 */
	public static boolean isValidDate(String dateStr, String fomart) {
		boolean convertSuccess = true;
		SimpleDateFormat format = new SimpleDateFormat(fomart);
		try {
			format.setLenient(false);
			format.parse(dateStr);
		} catch (ParseException e) {
			convertSuccess = false;
		}
		return convertSuccess;
	}

	/**
	 * 
	 * @param dateStr
	 * @param flag
	 *            0:"yyyy-MM-dd HH:mm:ss";1:"yyyy-MM-dd";2:"yyyy/MM/dd"
	 * @return
	 */
	public static boolean isValidDate(String dateStr, int flag) {
		if (flag == 0) {
			return isValidDate(dateStr, "yyyy-MM-dd HH:mm:ss");
		} else if (flag == 1) {
			return isValidDate(dateStr, "yyyy-MM-dd");
		} else if (flag == 2) {
			return isValidDate(dateStr, "yyyy/MM/dd");
		}
		return false;

	}

	public static String genericFormatDate() {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
		return formatter.format(new Date());
	}

	/**
	 * 得到某年某月的第一天
	 * 
	 * @param date
	 * @return
	 */
	public static Date getFirstDayOfMonth(Date date) {

		Calendar cal = Calendar.getInstance();
		if (date != null) {
			cal.setTime(date);
		}
		cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE));

		cal.set(Calendar.HOUR_OF_DAY, 00);
		cal.set(Calendar.MINUTE, 00);
		cal.set(Calendar.SECOND, 00);
		cal.set(Calendar.MILLISECOND, 00);

		return cal.getTime();
	}

	/**
	 * 得到某年某月的最后一天
	 * 
	 * @param date
	 * @return
	 */
	public static Date getLastDayOfMonth(Date date) {

		Calendar cal = Calendar.getInstance();
		if (date != null) {
			cal.setTime(date);
		}
		cal.set(Calendar.DAY_OF_MONTH, 1);

		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		cal.set(Calendar.MILLISECOND, 59);

		int value = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		cal.set(Calendar.DAY_OF_MONTH, value);

		return cal.getTime();

	}
	
	public static Timestamp getBefourOrAfterDay(int day){
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DATE, day);
		String strDate = converStringDate(c.getTime(), "yyyy-MM-dd HH:mm:ss");
		Timestamp time = getTimestampDate(strDate, "yyyy-MM-dd HH:mm:ss");
		return time;
	}
	
	public static boolean compareTime(Timestamp time, int day){
		Calendar calendar = Calendar.getInstance();
	    calendar.add(Calendar.DAY_OF_MONTH, day);
	    Timestamp compareTime = new Timestamp(calendar.getTimeInMillis());
	    if (time.after(compareTime)){
	    	return true;
	    };
	    return false;
	}
	
	
	/**
	 * 获取当前时间推后多少天
	 * @param day
	 * @param date
	 * @return
	 */
	public static Date getCurrentTimeByDay(int day, Date date) {
		Calendar todayStart = Calendar.getInstance();
		if (date != null) {
			todayStart.setTime(date);
		}
		todayStart.add(Calendar.DATE, day);
		return todayStart.getTime();
	}
	
	/**
	 * 获取当前时间推后多少月
	 * @param day
	 * @param date
	 * @return
	 */
	public static Date getCurrentTimeByMonth(int month, Date date) {
		Calendar todayStart = Calendar.getInstance();
		if (date != null) {
			todayStart.setTime(date);
		}
		todayStart.add(Calendar.MONTH, month);
		return todayStart.getTime();
	}
	
	/**
	 *	检测日期格式是否正确  
	 * @param time 日期 不包含时间 /和-都可以
	 * @return
	 */
	public static boolean checkTimeFormat(String time)
	{
		Pattern p;
		if(time.contains("-"))
		{
			p = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\-\\s]?((((0?" +"[13578])|(1[02]))[\\-\\-\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))" +"|(((0?[469])|(11))[\\-\\-\\s]?((0?[1-9])|([1-2][0-9])|(30)))|" +"(0?2[\\-\\-\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][12" +"35679])|([13579][01345789]))[\\-\\-\\s]?((((0?[13578])|(1[02]))" +"[\\-\\-\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))" +"[\\-\\-\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\-\\s]?((0?[" +"1-9])|(1[0-9])|(2[0-8]))))))"); 
		}else {
			p = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))"); 
			}
	 	return p.matcher(time).matches();
	}
	
	/**
	 * 获取当前时间往后推多少个小时
	 * @param hour
	 * @param date
	 * @return
	 */
	public static Date getCurrentEndTimeByHour(int hour, Date date) {
		Calendar todayStart = Calendar.getInstance();
		if (date != null) {
			todayStart.setTime(date);
		}
		todayStart.set(Calendar.MINUTE, 59);
		todayStart.set(Calendar.SECOND, 59);
		todayStart.set(Calendar.MILLISECOND, 999);
		todayStart.add(Calendar.HOUR_OF_DAY, hour);
		return todayStart.getTime();
	}
	
	/**
	 * 生成退款订单，规则 - 时间+退款类型(详见RefundType枚举类)+5位数字随机数
	 * @return
	 */
	public static String generateRefundNo(Integer type){
		String currentTime = TimeUtils.getCurrentTimeStr("yyyyMMddHHmmss");
		String random = RandomStringUtils.randomNumeric(5);
		return currentTime + type + random;
	}
	/**
	 * 获取当前月第一天是星期几
	 * @return
	 */
	public static Integer getWeekOfMonthFirstDay(String date){
		Date time = getMonthStartTime(date);
		Calendar c = Calendar.getInstance();
		c.setTime(time);
		int week = c.get(Calendar.DAY_OF_WEEK);
		/** 计算出来的星期为，星期日：1，星期一：2.....星期六：7 **/
		if(week == 1){
			return 7;
		}else{
			return week - 1;
		}
	}
	/**
	 * 获取一个月的开始时间，2016-02-01
	 * @return
	 */
	public static Date getMonthStartTime(String date){
		Calendar calendar = Calendar.getInstance();
		if(StringUtils.isEmpty(date)){
			calendar.setTime(new Date());
		}else{
			calendar.setTime(getTimestampDate(date, Constans.FORMAT_TIME_THREE));
		}
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getMinimum(Calendar.DAY_OF_MONTH));
        calendar.set(Calendar.HOUR_OF_DAY, 00);
        calendar.set(Calendar.MINUTE, 00);
        calendar.set(Calendar.SECOND, 00);
        calendar.set(Calendar.MILLISECOND, 00);
        return calendar.getTime();
	}
	/**
	 * 获取年
	 * @param date 时间参数
	 * @return
	 */
	public static Integer getYearByDate(String date){
		if(date == null){
			String year = convertTime(new Date(), "yyyy");
			return Integer.valueOf(year);
		}
		String year = convertTime(getTimestampDate(date, Constans.FORMAT_TIME_THREE), "yyyy");
		return Integer.valueOf(year);
	}
	/**
	 * 时间转换
	 * @param date 时间
	 * @param format 转换格式
	 * @return String 转换后的String类型时间字符串
	 */
	public static String convertTime(Date date, String format){
		if(StringUtils.isBlank(format)){
			format = "yyyy-MM-dd HH:mm:ss";
		}
		return new SimpleDateFormat(format).format(date);
	}
	/**
	 * 获取一个月的总天数
	 * @return
	 */
	public static int getMaxDayOfMonth(String date){
		Calendar aCalendar = Calendar.getInstance();
		if(StringUtils.isEmpty(date)){
			aCalendar.setTime(new Date());
		}else{
			aCalendar.setTime(getTimestampDate(date, Constans.FORMAT_TIME_THREE));
		}
		int day = aCalendar.getActualMaximum(Calendar.DATE);
		return day;
	}
	
	/**
	 * 获取之后的时间,单位秒
	 * @param price  秒
	 * @return
	 */
	public static Date getAfterTime(int price){
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.SECOND, price);   //2小时之后的时间
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String token_yxq = sdf.format(calendar.getTime());
		Date convertToDate = convertDate(token_yxq,"yyyy-MM-dd HH:mm:ss");
		return convertToDate;
	}
	
	public static void main(String[] args) {
		/*Date date = getCurrentEndTime(1, convertDate("2014-04-29", "yyyy-MM-dd"));
		System.out.println(converStringDate(date, "yyyy-MM-dd"));*/
		//System.out.println(converStringDate(getCurrentTimeByDay(1, new Date()), "yyyy-MM-dd HH:mm:ss"));
		//System.out.println(getTimeStampNumberFormat(getCurrentTime()));
		//System.out.println(converStringDate(getCurrentStartTime(-7, new Date()), "yyyy-MM-dd"));
	//	System.out.println(getTimeStampNumberFormat(getCurrentTime()));
//		System.out.println(convertToDate("2015-07-07"));
//		Date d = convertDate("2016-08", "yyyy-MM");
//		System.out.println(getLastDayOfMonth(d));
//		System.out.println(getFirstDayOfMonth(d));
//		System.out.println(checkLimitTime(getTimestampDateFmt("2016-07-17 00:00:01"), getTimestampDateFmt("2016-07-15 00:00:00"), 48*3600));;
		Calendar cal = Calendar.getInstance();
	    //int day = cal.get(Calendar.DATE);
	    /*int month = cal.get(Calendar.MONTH);
	    Date d = TimeUtils.convertDate("2016年08月", "yyyy年MM月");
	    System.out.println("2016年08月".substring(0, 4));*/
		/*SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss");
		Date dt;
		try {
			dt = sdf.parse("1801191657");
			String format = sdf2.format(dt);
			Date parse = sdf2.parse(format);
			return parse.getTime();
		} catch (ParseException e) {
			LOGGER.info("BCD时间转long出错");
		}*/
	   /* Date convertDate = convertDate("180119165710", "yyMMddHHmmss");
	    String convertTime = convertTime(convertDate, "yyyy-MM-dd HH:mm:ss");
	    convertTime = getCurrentTimeStr("SSS");
	    System.out.println(convertTime);*/
		SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss MMM dd, yyyy z",Locale.ENGLISH);
		try {
			Date a = dateFormat.parse("15:23:56 May 14, 2019 PST");
			System.out.println(a);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	
	
}
